package doc2db.stdstreams;

import doc2db.Launcher;
import doc2db.UserProp;
import java.awt.event.ActionEvent;
import java.io.PrintStream;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.text.JTextComponent;

/**
 *
 * @author yura
 */
public class MyOutPropMenu {
    private PrintStream stdout;
    private JTextComponent text;

    /**
     *
     * @param prSt stdout
     * @param textA TextComponent, for wat menu created
     */
    public MyOutPropMenu(PrintStream prSt, JTextComponent textA){
        stdout = prSt;
        text = textA;
    }

    /**
     * Create menu with: copy, clean, out to stdout, select all.
     * @return
     */
    public JPopupMenu getPopupMenu(){
        JPopupMenu m = new JPopupMenu();
        Icon cpimg = Launcher.getIcon("menu/editor/copy.png");
        Icon climg = Launcher.getIcon("menu/editor/delete.png");
        Icon saimg = Launcher.getIcon("menu/editor/selectAll.png");

        JMenuItem cp = new JMenuItem(new AbstractAction("Копировать", cpimg) {
            @Override
            public void actionPerformed(ActionEvent e) {
                text.copy();
            }
        });
        cp.setFont(UserProp.menuFont);
        m.add(cp);

        JMenuItem clean = new JMenuItem(new AbstractAction("Очистить", climg) {
            @Override
            public void actionPerformed(ActionEvent e) {
                text.setText("");
            }
        });
        clean.setFont(UserProp.menuFont);
        m.add(clean);

        JMenuItem out = new JMenuItem(new AbstractAction("Вывести в консоль") {
            @Override
            public void actionPerformed(ActionEvent e) {
                stdout.println(text.getText());
            }
        });
        out.setFont(UserProp.menuFont);
        m.add(out);

        JMenuItem selectAll = new JMenuItem(new AbstractAction("Выделить всё", saimg) {
            @Override
            public void actionPerformed(ActionEvent e) {
                text.selectAll();
            }
        });
        selectAll.setFont(UserProp.menuFont);
        m.add(selectAll);

        return m;
    }

}
